Thema Datum  Von Nutzer Rating
Antwort
06.05.2014 11:38:44 Alexandra
NotSolved
06.05.2014 18:44:05 Gast74905
NotSolved
06.05.2014 19:31:31 Gast38842
NotSolved
06.05.2014 21:48:25 Gast28128
NotSolved
07.05.2014 13:24:22 Alexandra
NotSolved
07.05.2014 13:30:48 Gast58804
NotSolved
19.05.2014 13:06:36 Alexandra
NotSolved
Blau Alle Kombinationen von Prozentzahlen, welche zur Summe 100% aufaddieren
19.05.2014 13:58:54 Gast21594
NotSolved
19.05.2014 15:03:45 Alexandra
NotSolved
19.05.2014 15:45:22 Gast71514
NotSolved

Ansicht des Beitrags:
Von:
Gast21594
Datum:
19.05.2014 13:58:54
Views:
1289
Rating: Antwort:
  Ja
Thema:
Alle Kombinationen von Prozentzahlen, welche zur Summe 100% aufaddieren

Hi again,

ok, da das inzwischen schon ziemlich lange andauert, gebe ich dir mal meine Lösung mit auf den Weg.

Option Explicit
Option Base 1

Sub Test()
  
  Dim rng As Excel.Range
  Dim aCombIdx() As Variant
  Dim aL() As Variant
  
  aCombIdx = Array(1, 1, 1, 1) '<- init, 4 Spalten
  aL = Array(0#, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1#)
  
  Application.ScreenUpdating = False
  
  With Range("A1")
    Call .CurrentRegion.Clear
    Set rng = .Resize(ColumnSize:=UBound(aCombIdx))
  End With
  
  Dim aTmp() As Variant
  Dim dblSum As Double
  Dim i As Long
  
  Do
    dblSum = 0
    aTmp = aCombIdx
    For i = 1 To UBound(aCombIdx)
      aTmp(i) = aL(aCombIdx(i))
      dblSum = dblSum + aTmp(i)
      If dblSum > 1# Then Exit For
    Next
    
    If dblSum = 1# Then
      rng.NumberFormat = "0%"
      rng.Value = aTmp
      Set rng = rng.Offset(RowOffset:=1)
    End If
    
  Loop While NextComb(aCombIdx, UBound(aL))
  
  Application.ScreenUpdating = True
  
End Sub

Private Function NextComb(ByRef Comb() As Variant, n As Long) As Boolean
  Dim i As Long
  i = LBound(Comb)
  Do Until i > UBound(Comb)
    If Comb(i) < n Then
      Comb(i) = Comb(i) + 1
      Exit Do
    Else
      Comb(i) = 1
      i = i + 1
    End If
  Loop
  NextComb = Not (i > UBound(Comb))
End Function

Gruß


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
06.05.2014 11:38:44 Alexandra
NotSolved
06.05.2014 18:44:05 Gast74905
NotSolved
06.05.2014 19:31:31 Gast38842
NotSolved
06.05.2014 21:48:25 Gast28128
NotSolved
07.05.2014 13:24:22 Alexandra
NotSolved
07.05.2014 13:30:48 Gast58804
NotSolved
19.05.2014 13:06:36 Alexandra
NotSolved
Blau Alle Kombinationen von Prozentzahlen, welche zur Summe 100% aufaddieren
19.05.2014 13:58:54 Gast21594
NotSolved
19.05.2014 15:03:45 Alexandra
NotSolved
19.05.2014 15:45:22 Gast71514
NotSolved